package ar.com.cooker.services.uow.ingredient;

import org.springframework.beans.factory.annotation.Autowired;

import ar.com.cooker.dao.IngredientDao;
import ar.com.cooker.model.Ingredient;
import ar.com.cooker.services.pojo.IngredientPojo;
import ar.com.cooker.services.uow.SaveAndUpdateUOW;
import ar.com.cooker.services.util.ConvertPojoToBO;

public class SaveAndUpdateIngredientUOW implements SaveAndUpdateUOW<IngredientPojo> {

	@Autowired
	private IngredientDao ingredientDao;

	public void execute(IngredientPojo u) {
		
		Ingredient i = ConvertPojoToBO.getIngredientPojoToIngredient(u);
		if(i.getId() == null){
			getIngredientDao().save(i);
		}else{
			getIngredientDao().update(i);
		}
	}

	public void setIngredientDao(IngredientDao ingredientDao) {
		this.ingredientDao = ingredientDao;
	}

	public IngredientDao getIngredientDao() {
		return ingredientDao;
	}



}
